package com.vsoontech.demo.componentlib;

import android.app.Application;

/**
 * Des:
 *
 * @author kingpengLin
 * @since 2019/9/26 11:58
 */
public class ServiceFactory {

    private static volatile ServiceFactory sInstance;
    private IMineService mMineService;
    private ILoginService mLoginService;

    public static ServiceFactory getInstance() {
        synchronized (ServiceFactory.class) {
            if (sInstance == null) {
                synchronized (ServiceFactory.class) {
                    sInstance = new ServiceFactory();
                }
            }
        }
        return sInstance;
    }

    /**
     * 通过反射，实例化模块的Applicaiton，并执行模块的Applicaiton的初始化操作
     */
    public void init(Application application) {
        for (String s : AppConfig.COMPONENT) {
            try {
                Class<?> clazz = Class.forName(s);
                Object object = clazz.newInstance();
                if (object instanceof IApplication) {
                    ((IApplication) object).init(application);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }

        }
    }

    public IMineService getMineService() {
        return mMineService;
    }

    public void setMineService(IMineService mineService) {
        mMineService = mineService;
    }

    public ILoginService getLoginService() {
        return mLoginService;
    }

    public void setLoginService(ILoginService loginService) {
        mLoginService = loginService;
    }
}
